package com.WebMentorPro.system.service.impl;

import com.WebMentorPro.system.common.ErrorCode;
import com.WebMentorPro.system.exception.BusinessException;
import com.WebMentorPro.system.mapper.ActivityMapper;
import com.WebMentorPro.system.model.dto.activity.ActivityQueryRequest;
import com.WebMentorPro.system.model.dto.activity.ActivityQueryRequestByStudent;
import com.WebMentorPro.system.model.entity.Activity;
import com.WebMentorPro.system.model.vo.ActivityVO;
import com.WebMentorPro.system.service.ActivityService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author bianxiaoyao
* @description 针对表【activity(异科导师活动表)】的数据库操作Service实现
* @createDate 2024-11-24 11:24:42
*/
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity>
    implements ActivityService {

    @Resource
    private ActivityMapper activityMapper;

    @Override
    public Page<ActivityVO> getQueryWrapper(Page<ActivityVO> pageParam, ActivityQueryRequest activityQueryRequest) {
        if (activityQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        // 自定义分页查询
        List<ActivityVO> activityVOS = activityMapper.getQuery(pageParam, activityQueryRequest);
        if (activityVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(activityVOS);
        return pageParam;
    }

    @Override
    public Page<ActivityVO> getQueryWrapperByMy(Page<ActivityVO> pageParam, ActivityQueryRequest activityQueryRequest, String teacherName) {
        if (activityQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        // 自定义分页查询
        List<ActivityVO> activityVOS = activityMapper.getQueryByMy(pageParam, activityQueryRequest, teacherName);
        if (activityVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(activityVOS);
        return pageParam;
    }

    @Override
    public Page<ActivityVO> getQueryByStudent(Page<ActivityVO> pageParam, ActivityQueryRequestByStudent activityQueryRequest, int teacherId) {
        if (activityQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        // 自定义分页查询
        List<ActivityVO> activityVOS = activityMapper.getQueryByStudent(pageParam, activityQueryRequest, teacherId);
        if (activityVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(activityVOS);
        return pageParam;
    }
}




